<template>
	<view>
		<view class="list" @click="turnToUpdate(teacher.id)" v-for="(teacher,index) in dataList">
			<view class="image">
				<image :src="teacher.imageUrl" mode="scaleToFill"></image>
			</view>
			<view class="info">
				<view class="name">
					<text>{{teacher.name}}</text>
				</view>
				<view class="price">
					<text>{{teacher.salePrice}}元/小时</text>
				</view>
			</view>
			<view class="state">
				<view class="btn">
					<text>{{teacher.vipPrice}}</text>
				</view>
			</view>
			<view class="icon">
				<view class="">
					<uni-icons type="forward" size="25"></uni-icons>
				</view>
			</view>
		</view>
		<uni-fab ref="fab" :pattern="pattern" :horizontal="horizontal" :vertical="vertical" :direction="direction"
			@trigger="trigger" @fabClick="fabClick" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'uni-fab',
				directionStr: '垂直',
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'horizontal',
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: '#007AFF',
					iconColor: '#fff'
				},
				is_color_type: false,
				dataList: [],
				pageSize: 8,
				total: '',
				pageNo: 1,
			};
		},
		// 触底的事件
		onReachBottom() {
			console.log('触底了');
			// 判断是否还有下一页数据
			if (this.pageNo * this.pageSize >= this.total) return uni.$showMsg('数据加载完毕！')
			// 让页码值自增 +1
			this.pageNo += 1
			// 重新获取列表数据
			this.getTeachersList(true)
		},
		onShow() {
			this.pageNo=1;
			this.pageSize=8;
			this.getTeachersList()		
		},
		methods:{
			async getTeachersList(onReachBottom) {
				const data = {
					goodsType: 1,
					storeId: uni.getStorageSync('storeId'),
					pageNo: this.pageNo,
					pageSize: this.pageSize,
				};
				const {
					data: res
				} = await uni.$http.post(
					`/store/storeGoodsQuery`, data
				);
				if (res.code !== 0) return uni.$showMsg(res.message);
				// 为数据赋值：通过展开运算符的形式，进行新旧数据的拼接
				if (onReachBottom) {
					this.dataList = [...this.dataList, ...res.data.data.records]
					return
				}
				this.dataList = res.data.data.records;
				this.total = res.data.data.total;
				console.log(res.data, '门店全部助教!');
			
			},
			fabClick() {
				uni.navigateTo({
					url: "/subpkg/AddTeacher/AddTeacher"
				})
			},
			turnToUpdate(id){
				uni.navigateTo({
					url: `/subpkg/UpdateTeacher/UpdateTeacher?id=${id}`
				})
			},
		}
	}
</script>

<style lang="scss">
	.list {
		margin-top: 2vh;
		height: 8vh;
		width: 100%;
		background-color: #fff;
		padding: 2vw;
		display: flex;
		align-items: center;
		position: relative;
		.info {
			margin-left: 5vw;

			.name {
				font-size: 30rpx
			}

			.price {
				margin-top: 1vh;
				color: #b8b5b8;
				font-size: 28rpx
			}
		}
		.icon{
			position: absolute;
			right: 5vw;
		}
		// .state{			
		// 	border: 1rpx solid #2196f3;
		// 	background-color: #f3f9ff;
		// 	color:#2196f3;
		// 	padding: 1vw;
		// 	border-radius: 10rpx;
		// 	font-size: 25rpx;
		// 	position: absolute;
		// 	right: 20vw;
		// }
		.state{		
			color:#2196f3;
			height: 5vh;
			font-size: 25rpx;
			position: absolute;
			right: 20vw;
			display: flex;
			flex-wrap: wrap;
		}
		.image {			
			width: 15vw;
			height: 15vw;			
			border-radius: 50%;

			image {
				width: 15vw;
				height: 15vw;
				border-radius: 50%;
			}
		}
	}
</style>